package com.sunyard.layoutit.application;

import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.routing.Router;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sunyard.layoutit.common.ApplicationConfig;
import com.sunyard.layoutit.common.DatabaseConfig;
import com.sunyard.layoutit.resource.LayoutitResource;
import com.sunyard.layoutit.service.SimpleStatusService;

/**
 * Rest探测类
 * @author gdl
 */
public class SimpleDefaultApplication extends Application{
	
	private static final Logger logger = LoggerFactory.getLogger(SimpleDefaultApplication.class);
	
	public SimpleDefaultApplication(){
		ApplicationConfig.init() ;
		DatabaseConfig.init(null);
		//当访问的资源不存在时默认由来处理
		logger.debug("初始化默认Application ...");
		setName("默认Application");
		setStatusService(new SimpleStatusService());
	}
	
	public synchronized Restlet createInboundRoot(){
		logger.info("初始化路由 ... ");
        Router router = new Router(getContext());
        //主页
        router.attach("/", LayoutitResource.class);
        
        return router;
    }
	
	
}
